package com.situ.object.dao.impl;

//import com.situ.manage.dao.UserDao;
//import com.situ.manage.entity.User;
//import com.situ.manage.utils.DBUtil;

import com.situ.object.dao.UserDao;
import com.situ.object.entity.User;
import com.situ.object.utils.DBUtil;

import java.util.List;

/*
* 用户实现类
* */
public class UserDaoImpl implements UserDao {

    //合成
    private DBUtil dbUtil = new DBUtil();
    //根据用户名查询用户信息
    @Override
    public User selectByUserName(String username) {
        String sql = "SELECT id,username,password,status from user where username = ?";
        dbUtil.queryOne(User.class,sql,username);
        return dbUtil.queryOne(User.class,sql,username);
    }
    //查询所有的用户信息
    @Override
    public List<User> selectAll() {
//        String sql = "SELECT * from user ";
        String sql = "SELECT id,username,password,status from user ";
        return dbUtil.query(User.class,sql);
    }

    //修改密码
    @Override
    public int updatePassword(Integer id, String password) {
        String sql = "update user set password = ? where id = ?";
        return dbUtil.update(sql,password,id);
    }

    //根据id查询用户信息
    @Override
    public User selectById(Integer id) {
        String sql = "SELECT id,username,password,status from user where id = ?";
        return dbUtil.queryOne(User.class,sql,id);
    }

    //添加管理员
    @Override
    public int addUser(User user) {
        String sql = "INSERT INTO `manage_system`.`user`(`username`, `password`, `status`) VALUES (?,?,?);";

        return dbUtil.update(sql,user.getUsername(),user.getPassword(),user.getStatus());
    }

  


}
